feat: Support clearing nullable fields with WorkOS::Null - #519
feat: Support clearing nullable fields with WorkOS::Null#519devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Optional parameters left as nil are omitted from the request body, so a nullable field such as an organization or user external_id could not be cleared through the SDK. Introduce a WorkOS::Null sentinel that serializes to JSON null, letting callers explicitly clear a field. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Original prompt from heather
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Closing in favor of #521. This PR was the non-breaking Ruby-local stopgap using a caller-facing
|
Description
Reported by a customer: there's no way to clear an organization's (or user's)
external_idvia the Ruby SDK.Root cause. Every generated service method builds a body hash and calls
.compact, and the hand-maintained runtime (base_client.rb) also doesbody.compact.to_json.Hash#compactdrops allnilvalues, so an explicitexternal_id: nilis stripped before serialization and never reaches the API as JSONnull. That's why:update_organization(external_id: nil)→nilstripped, field unchangedupdate_organization(external_id: "")→ API rejects empty string (422)client.request(body: { "external_id" => nil })→ still stripped bybase_client's.compactNet::HTTPPUT withJSON.generate({ "external_id" => nil })workedFix. Introduce a
WorkOS::Nullsentinel that serializes to JSONnull.nilkeeps its existing meaning ("omit / leave unchanged");WorkOS::Nullsends an explicitnullto clear the field. This is regeneration-safe — it lives entirely in the hand-maintained runtime, so no oagen-generated files are touched and every existing endpoint gains clear-field support automatically.Implementation:
lib/workos/null.rb— newWorkOS::Nullsentinel (to_json→"null").lib/workos/base_client.rb— body serialization now recursively convertsWorkOS::Null→ JSONnullafter.compact, so it works regardless of JSON encoder and even for nested values (e.g. clearing a singlemetadatakey).test/workos/test_null.rb— covers omit-vs-clear for orgs and users, the rawrequesthelper, and nested-hash null.README.md— documents "Clearing nullable fields".Documentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
The SDK README is updated in this PR. A follow-up to the Ruby SDK docs page may be worthwhile to mention
WorkOS::Null.Link to Devin session: https://app.devin.ai/sessions/127c630f46c54bc0be571814c75047e8